package club.xinghe.servlet.teacher;

import club.xinghe.biz.TeacherBiz;
import club.xinghe.entity.Class;
import club.xinghe.entity.Teacher;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

/**
 * 刘艺广
 */
@WebServlet("/teacher/ScoreAnalysisFirstServlet")
public class ScoreAnalysisFirstServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int eId= Integer.parseInt(request.getParameter("eId"));
        String eName=request.getParameter("eName");
        int gid= Integer.parseInt(request.getParameter("gid"));
        HttpSession session=request.getSession();

        Teacher teacher=(Teacher) session.getAttribute("teacher");
        int zId=teacher.getZy().getzId();

        TeacherBiz teacherBiz=new TeacherBiz();
        double avgScore=  teacherBiz.getZyAvg(zId,gid,eId);
        System.out.println(avgScore);
        List<Class> classList=teacherBiz.getAllClass(zId);

        request.setAttribute("classList",classList);
        request.setAttribute("avgScore",avgScore);
        request.setAttribute("eName",eName);
        request.setAttribute("eId",eId);
        request.setAttribute("zId",zId);
        request.setAttribute("gid",gid);
        request.getRequestDispatcher("/teacher/ScoreAnalysis.jsp").forward(request,response);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }
}
